<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ include file="/pub/siteinclud.jsp"%>

<html>
<head>
<script charset="utf-8" src="/editor/kindeditor.js"></script>
<title>信心发布</title>
<script type="text/javascript"
	src="<%=path %>/resources/js/shouye.js"></script>
<link rel="stylesheet"
	href="<%=request.getContextPath() %>/site/${SiteAccessPath}/css/css.css"
	type="text/css"/>
<link rel="stylesheet"
	href="<%=request.getContextPath() %>/site/${SiteAccessPath}/css/global.css"
	type="text/css"/>
<script type="text/javascript">
	var codemap = new Array(); 
	$(function(){
        $.ajax({
			url :"<%=request.getContextPath() %>/sys/code/getCodes", //要访问的后台地址
		    data: "code=<%=com.wing.sys.domain.Code.YBL_TYPE_CODE %>", //要发送的数据
		    type : 'POST', //使用get方法访问后台
		    dataType : 'json', //返回json格式的数据
		    success : function(data){
	   			var rows = data; 
	   			var aa="<ul>"
		    	$.each(rows, function(i, n){
		    		if(i==0){
		    			aa =aa+ $("#ybltype1").html()+"<li style='height:30px;float:left;margin:0 10px'><input checked type='radio' name='type_id' onclick='changeType()' value='"+n.code+"' id='"+n.id+"'/>&nbsp;&nbsp;<label for='"+n.id+"' >"+n.name+"</label></li>";
		    		}else{
		    			aa =aa+ $("#ybltype1").html()+"<li style='height:30px;float:left;margin:0 10px'><input type='radio' name='type_id' onclick='changeType()' value='"+n.code+"' id='"+n.id+"'/>&nbsp;&nbsp;<label for='"+n.id+"' >"+n.name+"</label></li>";
		    		}
		        }); 
		        $("#ybltype1").html(aa+"</ul>");
				changeType();
		    }
		});	
			
			$.formValidator.initConfig({formid:"informationform",alertmessage:false,onerror:function(msg){alert(msg)}});
			$("#editor_id").formValidator().inputValidator({min:10,onerror:"发帖内容不得少于10个字符"}).inputValidator({max:10240,onerror:"内容超长"});
            $("#title").formValidator().inputValidator({min:5,max:255,onerror:"标题为5-255个字符"});
            
	})
	function changeType(){
		var code = $("input[@type=radio][name=type_id][checked]").val()
		var aa = codemap[code];
		if(!aa){
			$.ajax({
				url :"<%=request.getContextPath() %>/sys/code/getCodes", //要访问的后台地址
			    data: "code="+code, //要发送的数据
			    type : 'POST', //使用get方法访问后台
			    dataType : 'json', //返回json格式的数据
			    success : function(data){
		   			var rows = data; 
		   			aa = "<ul>";
			    	$.each(rows, function(i, n){
			    		if(i==0){
			    			aa = aa+"<li style='height:30px;float:left;margin:0 10px'><input type='radio' name='type_id2' checked value='"+n.code+"' id='"+n.id+"'/>&nbsp;&nbsp;<label for='"+n.id+"'>"+n.name+"</label></li>";
			    		}else{
			    			aa = aa+"<li style='height:30px;float:left;margin:0 10px'><input type='radio' name='type_id2' value='"+n.code+"' id='"+n.id+"'/>&nbsp;&nbsp;<label for='"+n.id+"'>"+n.name+"</label></li>";
			    		}
			        }); 
			        codemap[code]=aa;
					$("#ybltype2").html(aa+"</ul>");
			    }
			});	
		}else{
			$("#ybltype2").html(aa);
		}
	}
	function save(){
		document.getElementById("editor_id").value=KE.html("editor_id");
		if($.formValidator.pageIsValid()){
			var options = {
				type: 'POST',
				async: false,
				success: function(msg) {
					if(msg=="codenull"){
						alert("验证码不得为空");
					}else if(msg=="failure"){
						alert("验证码不正确，请重新出入");
						$("veryCode").attr("value","");
					}else{
						alert("信息发布成功");
						window.close();
					}
				}
			}
			$('#informationform').ajaxSubmit(options);
		}
		changeImg();
	}
	function changeImg(){      
		var imgSrc = $("#imgObj");
		var src = imgSrc.attr("src");  
		imgSrc.attr("src",chgUrl(src));     
	}     
	//时间戳     
	//为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳     
	function chgUrl(url){         
		var timestamp = (new Date()).valueOf();         
		urlurl = url.substring(0,17);         
		if((url.indexOf("&")>=0)){             
			urlurl = url + "&tamp=" + timestamp;         
		}else{             
			urlurl = url + "?timestamp=" + timestamp;         
		}         
		return urlurl;     
	} 
</script>
</head>

<body>

<%@ include file="header.jsp" %>
<form id="informationform" action="<%=path%>/ext/information/send" method="post">
<input type="hidden" name="site_id" value="yblsite01"/>
<div class="position">您的位置：<a href="index">首页</a> > 信息发布</div>
<%if(userId!=null){
	%>
	<div class="fb_main">
		<img src="<%=request.getContextPath() %>/site/${SiteAccessPath}/images/fb.gif" />
	    <div class="bclass">
	   	  	<b class="left">大类：</b>
	   	  	<div id="ybltype1"></div>
	    </div>
	  	<div class="sclass">
	  	  	<b class="left">小类：</b>
	  	  	<div id="ybltype2"></div>
	    </div>
	</div>
	<div class="state"><strong>说明：</strong>1、请正确选择发布信息的分类。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2、禁止发布反动、黄色及一切非法的文字和图片。</div>
	<div class="edit">
	  <div class="edit_title"><b>信息标题:</b><input type="text" name="title" id="title" class="edut_input"/></div>
	    <div class="describe"><b>发布信息具体内容描述</b>（文字10---5000）</div>
	    <div class="editor">
			<textarea id="editor_id" name="content" style="width:700px;height:300px;"></textarea>
		    <script>
		    	KE.show({
					id : 'editor_id',
					urlType:'absolute',
					imageUploadJson : '<%=request.getContextPath() %>/res/upload?c=<%=userId %>/',
					fileManagerJson : '<%=request.getContextPath() %>/res/show?path=<%=userId %>/',
					allowFileManager : true
				});
		    </script>
		</div>
	    <div class="button"><input type="button" name="button" onclick="save()" value="发布" />
	    <input id="veryCode" name="veryCode" type="text"/>               
	    <img id="imgObj" alt="" src="<%=path %>/sys/getImg"/>               
	    <a href="javascript:changeImg()" >换一张</a>                             
	    <div id="info"></div> 
	    </div>
	</div>
	<%
}else{
	%>
	<div class="notlogin_div">
	您还没有登录，请先登录在发布信息！
	</div>
<%
} 
%>

</form>
<%@ include file="footer.jsp" %>
</body>
</html>






